package cn.tedu.dict.controller;

import cn.tedu.base.response.JsonResult;
import cn.tedu.dict.pojo.dto.DictQuery;
import cn.tedu.dict.pojo.dto.DictSaveParam;
import cn.tedu.dict.pojo.vo.DictVO;
import cn.tedu.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/dict/")
@Slf4j
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("select")
    public JsonResult select(DictQuery dictQuery) {
        log.debug("查询字典参数：{}", dictQuery);
        List<DictVO> list = dictService.selectDict(dictQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveDict(DictSaveParam dictSaveParam) {
        log.debug("保存字典参数：{}", dictSaveParam);
        dictService.saveDict(dictSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteDictById(@PathVariable Long id) {
        log.debug("删除字典参数：{}", id);
        dictService.deleteDictById(id);
        return JsonResult.ok();
    }

}
